
import React from 'react';
import { _ } from '../../util/pcPublic';

export default class WfNativeRadio extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        const { options = [], fieldAttr = {}, value, viewAttr, domKey } = this.props;
        const { selectattr } = fieldAttr;
        const { fieldshowtypes } = selectattr;//横向是1 竖向是2
        let radios = [];
        let isRequired = viewAttr == 3 && value == "";
        options.map(item => {
            if (item.value !== "") {
                radios.push(
                    <span className="wf-radio-item"
                        style={{
                            display: fieldshowtypes == 2 ? "block" : "inline-block",
                        }}
                        id={item.value}
                        onClick={(e) => this.onClick(e)}
                    >
                        <input type="radio" className="wf-radio" id={item.value} value={item.value} checked={item.value == value} disabled={viewAttr == 1} />
                        <label id={item.value} className="wf-radio-label" >{item.label}</label>
                    </span>
                );
            }
        })
        return (
            <div className='wf-nativeRadio'>
                <div className='wf-nativeRadio-radioGroup'>
                    {radios}
                </div>
                {isRequired && <div className="wf-radio-required-icon">
                    <img src="/images/BacoError_wev9.png" align="absmiddle" />
                </div>
                }
            </div>
        )
    }

    onClick = (e) => {
        const { onChange, supportCancel, value, viewAttr } = this.props;
        if (viewAttr == 1) return;
        let v = e.target.id;
        if (value == v && supportCancel) v = "";
        onChange(v);
    }

}